<template>
	<view>
		<!-- <cmd-nav-bar :title="'顶部导航栏'"></cmd-nav-bar> -->
		<!-- 在使用顶部和底部导航栏时,top-bottom -->
		<cmd-page-body type="bottom">
		  <!-- #ifdef H5 -->
		  <cmd-transition name="fade-up">
		    <index v-if="current == 0"></index>
		    <cart v-if="current == 1"></cart>
		  </cmd-transition>
		  <!-- #endif -->
		  <!-- 单使用顶部导航时，非H5端下v-if显示，可以在mounted后 -->
		  <!-- #ifndef H5 -->
		  <cmd-transition v-if="current == 0" name="fade-up">
		    <index></index>
		  </cmd-transition>
		  <cmd-transition v-if="current == 1" name="fade-up">
		    <type></type>
		  </cmd-transition>
		  <cmd-transition v-if="current == 2" name="fade-up">
			<cart></cart>
		  </cmd-transition>
		  <cmd-transition v-if="current == 3" name="fade-up">
		    <mine></mine>
		  </cmd-transition>
		  <!-- #endif -->
		</cmd-page-body>
		<!-- 底部导航栏 -->
		<cmd-bottom-nav @click="getBottomNavCurrent" :current="current" :list="list"></cmd-bottom-nav>
	</view>
</template>

<script>
	import cmdBottomNav from "@/components/cmd-bottom-nav/cmd-bottom-nav.vue"
	import cmdPageBody from "@/components/cmd-page-body/cmd-page-body.vue"
	import index from "./tabs/index/index"
	// import cart from "./tabs/cart/cart"
	import cart from "../shop/shopcar"
	import type from "./tabs/type/type"
	import mine from "./tabs/mine/mine"
	export default {
		components: {
			cmdBottomNav,
			cmdPageBody,
			index,
			cart,
			type,
			mine
		},
		data() {
			return {
				current: 0,
				list:[{
				    "pagePath": "pages/shopPages/tabs/index/index",
				    "text": "首页",
				    "icon": "home"
				  },{
				    "pagePath": "pages/shopPages/tabs/index/index",
				    "text": "分类",
				    "icon": "list"
				  },{
				    "pagePath": "pages/shopPages/tabs/index/index",
				    "text": "购物车",
				    "icon": "shopping-cart",
					"badgeNum":0,
				  },
				  {
				    "pagePath": "pages/shopPages/tabs/cart/cart",
				    "text": "我的",
				    "icon": "user"
				  }
				]
			}
		},
		onLoad(e) {
			if(e&&e.current){
				this.current = e.current;
			}
			this.mallShoppingcar_list()
		},
		methods:{
			getBottomNavCurrent(e){
				this.current = e.select;
				this.mallShoppingcar_list()
			},
			//获取购物车总数
			mallShoppingcar_list() {
				var _this=this;
				uni.request({
					url:this.$API.mallShoppingcar_list,
					method:"POST",
					data:{u_id:_this.userid},
					header:this.$API.get_head(),
					success: (res) => {
						_this.list[2].badgeNum=res.data.records;
					},
					fail: () => {
						uni.showToast({
							title:"加载失败",
							icon:'none'
						})
					 }
				})
			},
		}
		
	}
</script>

<style lang="scss">
	.body{
	    /*距离顶部范围应该在118-122范围内*/
	    padding-bottom: 118upx;
	}
	
</style>